﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.GualityScheme;
using MVC_System.DTO.ProductionOrdersDTO;
using Newtonsoft.Json;
using WMS_MAV;
using Minio.Exceptions;
using System.Configuration;
using ConfigurationManager = System.Configuration.ConfigurationManager;
using Minio;

namespace MVC_System.Controllers
{
    public class ProductionOrdersController : Controller
    {
        private readonly IConfiguration _configuration;
        public ProductionOrdersController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        
        /// <summary>
        /// 显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionOrdersShowView()
        {
            return View();
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ProductionOrdersShow(ProductionOrdersShowDTO dto)
        {
            //HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            //string url = _configuration["Url"] + "HysSwagger/api/ProductionOrders/GetProductionOrders?OrderNumber=" + dto.OrderNumber + "&State=" + dto.State + "&AddTime=" + dto.AddTime;
            //var respomse = await client.GetAsync(url);
            //return Json(respomse);
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/ProductionOrders/GetProductionOrders?OrderNumber=" + dto.OrderNumber + "&State=" + dto.State + "&AddTime=" + dto.AddTime;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionOrdersAddView()
        {
            return View();
        }
        /// <summary>
        /// 成品表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> FinishedProductShowModel(FinishedProductShowModelDTO dto)
        {
            //HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            //string url = _configuration["Url"] + "HysSwagger/api/ProductionOrders/GetProductionOrders?OrderNumber=" + dto.OrderNumber + "&State=" + dto.State + "&AddTime=" + dto.AddTime;
            //var respomse = await client.GetAsync(url);
            //return Json(respomse);
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "RawApi/api/FinishedProducts/ShowFinis";
            string list = JsonConvert.SerializeObject(dto.finishedProductId);
            var respomse = await client.PostAsync(url,list);
            return Json(respomse);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ProductionOrdersAdd(ProductionOrdersAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/ProductionOrders/AddProductionOrders";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        public IActionResult ProductionOrdersUpdateView() 
        {
            return View();
        }
        public IActionResult ProductionOrdersModelView()
        {
            return View();
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ProductionOrdersModel(ProductionOrdersModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/ProductionOrders/GetProductionOrdersModel?ProductionOrdersId=" + dto.ProductionOrdersId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ProductionOrdersUpdate(ProductionOrdersUpdateDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/ProductionOrders/UpdateProductionOrders";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> ProductionOrdersDelete(ProductionOrdersDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/ProductionOrders/DeleteProductionOrders";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
    } 
}
